package com.training1.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;



import com.training1.core.dto.APIResultDto;
import com.training1.core.dto.MessageListDto;
import com.training1.core.entity.NoticeMsgEntity;
import com.training1.core.modules.service.NoticeMsgService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;

@Api(value = "/api/message", description = "获取消息列表") // Swagger annotation
@RestController
@RequestMapping("/api/message")
public class GetMessageListController {
	@Resource
	private NoticeMsgService noticeMsgService;
	
	@ApiOperation(value = "获取该所有消息")
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	public APIResultDto<Object> getMessageList(String cellphone){
		APIResultDto<Object> result =new APIResultDto<>();
		Map<String,Object>map=new HashMap<String, Object>();
		List<NoticeMsgEntity>nm=noticeMsgService.getMessageList(cellphone);
		if(nm!=null){
			result.setStatus(APIResultDto.SUCCESS_OK);
			result.setErrorCode("1");
			if(nm.isEmpty()){
				result.setMessage("您还没有收到消息");
			}else{
				List<MessageListDto>helpList=new ArrayList<MessageListDto>();
				for(int i=0;i<nm.size();i++){
					MessageListDto ml=new MessageListDto();
					ml.setContent(nm.get(i).getContent());
					ml.setMsgTitle(nm.get(i).getMsgTitle());
					ml.setPublishStartTime(nm.get(i).getPublishStartTime());
					ml.setType(nm.get(i).getType());
					helpList.add(ml);
				}
				map.put("helpList", helpList);
				result.setData(map);
			}
		}else{
			result.setStatus(APIResultDto.SYSTEM_ERROR);
			result.setErrorCode("0");
		}
		
		return result;
	}
}
